<?php
namespace app\store\controller\food\applet;

use app\store\controller\food\Controller;
use hema\wechat\Driver;
use think\facade\View;

/**
 * 体验用户管理
 */
class Test extends Controller
{
    /**
     * 列表
     */
    public function index()
    {
		$wx = new Driver;
        $list = $wx->getTestUser($this->applet_id);
		return View::fetch('index', compact('list'));	
    }

    /**
     * 添加
     */
    public function add()
    {
        if (!$this->request->isAjax()) {
            return View::fetch();
        }
        $data = $this->postData('data');
        $wx = new Driver;
		$result = $wx->addTestUser($this->applet_id,$data['wechatid']);
		if($result['errcode']!=0){
			return $this->renderError('code：'.$result['errcode'].'，msg：'.$result['errmsg']);
		}
		return $this->renderSuccess('添加成功',url('food.applet.test/index'));
    }

    /**
     * 删除
     */
    public function delete(string $id)
    {
    	$wx = new Driver;
    	$result = $wx->delTestUser($this->applet_id,$id);
        if($result['errcode']!=0){
			return $this->renderError('code：'.$result['errcode'].'，msg：'.$result['errmsg']);
		}
		return $this->renderSuccess('删除成功');
    }

}
